package com.gooddare.view.component 
{
	import com.gooddare.controller.ApplicationFacade;
	import com.gooddare.model.ModelLocator;
	import com.gooddare.model.vo.GridviewItemVO;
	import com.riatimes.mvc.view.BaseComponent;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import com.greensock.TweenMax;
	/**
	 * ...
	 * @author Lyleff
	 */
	public class TagsItemComponent extends BaseComponent
	{
		private var vo:GridviewItemVO;
		private var txt:TextField;
		private var tfm:TextFormat;
		public var bimg:String;
		public var msg:String;
		public var id:int;
		public function TagsItemComponent(id:int,vo:GridviewItemVO) 
		{
			this.vo = vo;
			this.buttonMode = true;
			this.mouseChildren = false;
			this.id = id;
		}
		override public function initUI():void {
			tfm = new TextFormat();
			tfm.font = "Candara";
			tfm.color = 0x5f5f5f;
			tfm.size = 14;
			txt = new TextField();
			
			txt.defaultTextFormat = tfm;
			txt.htmlText ="<u>"+ vo.title+"</u>";
			txt.autoSize = TextFieldAutoSize.LEFT;
			txt.selectable = false;
			this.addChild(txt);
		}
		override public function initEvent (b:Boolean = true) : void {
			if (b) {
				this.addEventListener(MouseEvent.ROLL_OVER, __mouseRollEventHandle);
				this.addEventListener(MouseEvent.ROLL_OUT, __mouseRollEventHandle);
				this.addEventListener(MouseEvent.CLICK, __mouseClickEventHandle);
			}else {
				this.removeEventListener(MouseEvent.ROLL_OVER, __mouseRollEventHandle);
				this.removeEventListener(MouseEvent.ROLL_OUT, __mouseRollEventHandle);
				this.removeEventListener(MouseEvent.CLICK, __mouseClickEventHandle);
			}
		}
		
		private function __mouseClickEventHandle(e:MouseEvent):void 
		{
			this.bimg = vo.bimg;
			this.msg = vo.msg;
			ModelLocator.playerId = this.id;
			var facade:ApplicationFacade = ApplicationFacade.getInstance();
			facade.sendNotification(ApplicationFacade.EVENT_DATA_HOMEPIC_POST, this);
		}
		
		private function __mouseRollEventHandle(e:MouseEvent):void 
		{
			switch(e.type) {
				case MouseEvent.ROLL_OVER:
					TweenMax.to(this, .5, { tint:0xff00ff } );
				break;
				case MouseEvent.ROLL_OUT:
					TweenMax.to(this, .5, { tint:0x5f5f5f } );
				break;
			}
			
		}
		
	}

}